package com.example.a79273.shandianban;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.menu.ExpandedMenuView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.a79273.shandianban.R;

public class SearchActivity extends BaseActivity implements View.OnClickListener {

    private EditText mEditTextInput;
    private TextView mTextViewSearch;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);

        initView();
        initData();
        setData();
        setListener();
    }

    private void setListener() {
        mEditTextInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if( !TextUtils.isEmpty(s)) {
                    mTextViewSearch.setText("搜索");
                }else{
                    mTextViewSearch.setText("取消");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        mTextViewSearch.setOnClickListener(this);

    }

    private void setData() {
    }

    private void initData() {
    }

    private void initView() {
        mEditTextInput = (EditText) findViewById(R.id.et_search_input);
        mTextViewSearch = (TextView) findViewById(R.id.tv_search_search);
    }

    //所有的点击事件
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case  R.id.tv_search_search:
                String inputStr = mTextViewSearch.getText().toString();
                if("取消".equals(inputStr)) {//取消的时候
                    finish();
                }else {//搜索信息

                }
                break;
        }
    }
}
